package gases.as3.util
{
	import flash.utils.Dictionary;
	/**
	 *把XML转为hash输出 
	 * @author helloworld
	 * 
	 */	
	public class XMLTransHash
	{
		public function XMLTransHash()
		{
		}
		public static var layerLevel:int = 1;
		
		public static function XMLTransHashForXML(xml:XML):Array
		{
			var retArr:Array = new Array(); 
			
			var xmlList:XMLList = xml.children();
			if(xmlList.length() > 0)
			{
				retArr = retArr.concat(retArrayAttributesInXMLList(xmlList,"",layerLevel));
			}
			return retArr;
		}
		
		
		public static function retArrayAttributesInXMLList(xmlList:XMLList,id:String,layer:int):Array
		{
			var retArr:Array = new Array();
			for(var i:int=0;i<xmlList.length();i++)
			{
				var xml:XML = xmlList[i];
				var obj:Object = new Object();
				obj["parent"] = id;
				obj["localname"] = xml.localName().toString();
				obj["layerLevel"] = layer;
				var attributesList:XMLList = xml.attributes();
				for(var j:int=0;j<attributesList.length();j++)
				{
					var nm:String = attributesList[j].name();
					obj[nm] = attributesList[j];
				}
				if(xml.children().length() >0)
				{
					retArr = retArr.concat(retArrayAttributesInXMLList(xml.children(),xml.@id.toString(),layer++));
				}
				retArr.push(obj);
			}
			return retArr;
		}
		
		
	}
}